<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>platform_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_useragent_platform_test.js.html">platform_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.userAgent.platformTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.userAgent.platformTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.testing.MockUserAgent&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line21"></a>goog.require(&#39;goog.userAgent.platform&#39;);
<a name="line22"></a>
<a name="line23"></a>var mockAgent;
<a name="line24"></a>
<a name="line25"></a>function setUp() {
<a name="line26"></a>  mockAgent = new goog.testing.MockUserAgent();
<a name="line27"></a>  mockAgent.install();
<a name="line28"></a>}
<a name="line29"></a>
<a name="line30"></a>function tearDown() {
<a name="line31"></a>  mockAgent.dispose();
<a name="line32"></a>  updateUserAgentUtils();
<a name="line33"></a>}
<a name="line34"></a>
<a name="line35"></a>function updateUserAgentUtils() {
<a name="line36"></a>  goog.userAgent.PLATFORM = goog.userAgent.determinePlatform_();
<a name="line37"></a>  goog.userAgent.initPlatform_();
<a name="line38"></a>
<a name="line39"></a>  // Unfortunately we can&#39;t isolate the useragent setting in a function
<a name="line40"></a>  // we can call, because things rely on it compiling to nothing when
<a name="line41"></a>  // one of the ASSUME flags is set, and the compiler isn&#39;t smart enough
<a name="line42"></a>  // to do that when the setting is done inside a function that&#39;s inlined.
<a name="line43"></a>  goog.userAgent.MAC = goog.userAgent.detectedMac_;
<a name="line44"></a>  goog.userAgent.WINDOWS = goog.userAgent.detectedWindows_;
<a name="line45"></a>  goog.userAgent.LINUX = goog.userAgent.detectedLinux_;
<a name="line46"></a>  goog.userAgent.X11 = goog.userAgent.detectedX11_;
<a name="line47"></a>  goog.userAgent.ANDROID = goog.userAgent.detectedAndroid_;
<a name="line48"></a>  goog.userAgent.IPHONE = goog.userAgent.detectedIPhone_;
<a name="line49"></a>  goog.userAgent.IPAD = goog.userAgent.detectedIPad_;
<a name="line50"></a>
<a name="line51"></a>  goog.userAgent.platform.VERSION =
<a name="line52"></a>      goog.userAgent.platform.determineVersion_();
<a name="line53"></a>}
<a name="line54"></a>
<a name="line55"></a>function testWindows() {
<a name="line56"></a>  mockAgent.setNavigator({platform: &#39;Win32&#39;});
<a name="line57"></a>
<a name="line58"></a>  var win98 = &#39;Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98; Win 9x 4.90)&#39;;
<a name="line59"></a>  var win2k = &#39;Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.0; en-US)&#39;;
<a name="line60"></a>  var xp = &#39;Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.1; en-US)&#39;;
<a name="line61"></a>  var vista = &#39;Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)&#39;;
<a name="line62"></a>  var win7 = &#39;Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.1; en-US)&#39;;
<a name="line63"></a>  var win81 = &#39;Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko&#39;;
<a name="line64"></a>
<a name="line65"></a>  mockAgent.setUserAgentString(win98);
<a name="line66"></a>  updateUserAgentUtils();
<a name="line67"></a>  assertEquals(&#39;0&#39;, goog.userAgent.platform.VERSION);
<a name="line68"></a>
<a name="line69"></a>  mockAgent.setUserAgentString(win2k);
<a name="line70"></a>  updateUserAgentUtils();
<a name="line71"></a>  assertEquals(&#39;5.0&#39;, goog.userAgent.platform.VERSION);
<a name="line72"></a>
<a name="line73"></a>  mockAgent.setUserAgentString(xp);
<a name="line74"></a>  updateUserAgentUtils();
<a name="line75"></a>  assertEquals(&#39;5.1&#39;, goog.userAgent.platform.VERSION);
<a name="line76"></a>
<a name="line77"></a>  mockAgent.setUserAgentString(vista);
<a name="line78"></a>  updateUserAgentUtils();
<a name="line79"></a>  assertEquals(&#39;6.0&#39;, goog.userAgent.platform.VERSION);
<a name="line80"></a>
<a name="line81"></a>  mockAgent.setUserAgentString(win7);
<a name="line82"></a>  updateUserAgentUtils();
<a name="line83"></a>  assertEquals(&#39;6.1&#39;, goog.userAgent.platform.VERSION);
<a name="line84"></a>
<a name="line85"></a>  mockAgent.setUserAgentString(win81);
<a name="line86"></a>  updateUserAgentUtils();
<a name="line87"></a>  assertEquals(&#39;6.3&#39;, goog.userAgent.platform.VERSION);
<a name="line88"></a>}
<a name="line89"></a>
<a name="line90"></a>function testMac() {
<a name="line91"></a>  // For some reason Chrome substitutes _ for . in the OS version.
<a name="line92"></a>  var chrome = &#39;Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US)&#39; +
<a name="line93"></a>      &#39;AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.49 Safari/532.5&#39;;
<a name="line94"></a>
<a name="line95"></a>  var ff = &#39;Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;&#39; +
<a name="line96"></a>      &#39;rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB6&#39;;
<a name="line97"></a>
<a name="line98"></a>  // An old camino version that doesn&#39;t report a Mac version.
<a name="line99"></a>  var camino = &#39;Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.11)&#39; +
<a name="line100"></a>      &#39;Gecko/20071128 Camino/1.5.4&#39;;
<a name="line101"></a>
<a name="line102"></a>  mockAgent.setNavigator({platform: &#39;IntelMac&#39;});
<a name="line103"></a>
<a name="line104"></a>  mockAgent.setUserAgentString(chrome);
<a name="line105"></a>  updateUserAgentUtils();
<a name="line106"></a>  assertEquals(&#39;10.5.8&#39;, goog.userAgent.platform.VERSION);
<a name="line107"></a>
<a name="line108"></a>  mockAgent.setUserAgentString(ff);
<a name="line109"></a>  updateUserAgentUtils();
<a name="line110"></a>  assertEquals(&#39;10.5&#39;, goog.userAgent.platform.VERSION);
<a name="line111"></a>
<a name="line112"></a>  mockAgent.setUserAgentString(camino);
<a name="line113"></a>  updateUserAgentUtils();
<a name="line114"></a>  assertEquals(&#39;10&#39;, goog.userAgent.platform.VERSION);
<a name="line115"></a>}
<a name="line116"></a>
<a name="line117"></a>function testChromeOnAndroid() {
<a name="line118"></a>  // Borrowing search&#39;s test user agent string for android.
<a name="line119"></a>  var uaString = &#39;Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus&#39; +
<a name="line120"></a>      &#39; Build/ICL53F) AppleWebKit/535.7 (KHTML, like Gecko) &#39; +
<a name="line121"></a>      &#39;Chrome/18.0.1025.133 Mobile Safari/535.7&#39;;
<a name="line122"></a>
<a name="line123"></a>  // Need to set this lest the testing platform be used for detection.
<a name="line124"></a>  mockAgent.setNavigator({platform: &#39;Android&#39;});
<a name="line125"></a>
<a name="line126"></a>  mockAgent.setUserAgentString(uaString);
<a name="line127"></a>  updateUserAgentUtils();
<a name="line128"></a>  assertTrue(goog.userAgent.ANDROID);
<a name="line129"></a>  assertEquals(&#39;4.0.2&#39;, goog.userAgent.platform.VERSION);
<a name="line130"></a>}
<a name="line131"></a>
<a name="line132"></a>function testAndroidBrowser() {
<a name="line133"></a>  var uaString = &#39;Mozilla/5.0 (Linux; U; Android 2.3.4; fr-fr;&#39; +
<a name="line134"></a>      &#39;HTC Desire Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko)&#39; +
<a name="line135"></a>      &#39;Version/4.0 Mobile Safari/533.1&#39;;
<a name="line136"></a>
<a name="line137"></a>  // Need to set this lest the testing platform be used for detection.
<a name="line138"></a>  mockAgent.setNavigator({platform: &#39;Android&#39;});
<a name="line139"></a>
<a name="line140"></a>  mockAgent.setUserAgentString(uaString);
<a name="line141"></a>  updateUserAgentUtils();
<a name="line142"></a>  assertTrue(goog.userAgent.ANDROID);
<a name="line143"></a>  assertEquals(&#39;2.3.4&#39;, goog.userAgent.platform.VERSION);
<a name="line144"></a>}
<a name="line145"></a>
<a name="line146"></a>function testIPhone() {
<a name="line147"></a>  // Borrowing search&#39;s test user agent string for the iPhone.
<a name="line148"></a>  var uaString = &#39;Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; &#39; +
<a name="line149"></a>      &#39;en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 &#39; +
<a name="line150"></a>      &#39;Mobile/8A293 Safari/6531.22.7&#39;;
<a name="line151"></a>
<a name="line152"></a>  // Need to set this lest the testing platform be used for detection.
<a name="line153"></a>  mockAgent.setNavigator({platform: &#39;iPhone&#39;});
<a name="line154"></a>
<a name="line155"></a>  mockAgent.setUserAgentString(uaString);
<a name="line156"></a>  updateUserAgentUtils();
<a name="line157"></a>  assertTrue(goog.userAgent.IPHONE);
<a name="line158"></a>  assertEquals(&#39;4.0&#39;, goog.userAgent.platform.VERSION);
<a name="line159"></a>}
<a name="line160"></a>
<a name="line161"></a>function testIPad() {
<a name="line162"></a>  // Borrowing search&#39;s test user agent string for the iPad.
<a name="line163"></a>  var uaString = &#39;Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; ja-jp) &#39; +
<a name="line164"></a>      &#39;AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 &#39; +
<a name="line165"></a>      &#39;Safari/6533.18.5&#39;;
<a name="line166"></a>
<a name="line167"></a>  // Need to set this lest the testing platform be used for detection.
<a name="line168"></a>  mockAgent.setNavigator({platform: &#39;iPad&#39;});
<a name="line169"></a>
<a name="line170"></a>  mockAgent.setUserAgentString(uaString);
<a name="line171"></a>  updateUserAgentUtils();
<a name="line172"></a>  assertTrue(goog.userAgent.IPAD);
<a name="line173"></a>  assertEquals(&#39;4.2.1&#39;, goog.userAgent.platform.VERSION);
<a name="line174"></a>}
</pre>


</body>
</html>
